package com.taotao.search.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/**
 * 全局异常处理
 * @author created by wq
 * @date   Sep 2, 2017---12:03:05 PM
 * @return
 * @throws Exception<br/>
 *==========History========== <br/>
 * taotao-search-web Sep 2, 2017
 */

public class GlobalExceptionResolver implements HandlerExceptionResolver{

	private static Logger logger = Logger.getLogger(GlobalExceptionResolver.class);
	
	/**
	 *全局异常处理 ：先写日志，然后短信、邮件通知开发者；然后给出友好界面。
	 */
	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
			Object handlder,Exception e) {
		//1.写日志文件
		logger.error("运行时异常", e);
		//2.发送短信或邮件  ：发短信用第三方短信平台 ，发邮件用jmail包 
		//3.给出友好页面
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("error/exception");
		modelAndView.addObject("message", "您的网络异常，请稍后重试。。。");
		return modelAndView;
	}

}
